<?php

namespace App\Http\Requests;

use App\Util\Result;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;

class HouseRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'shop_id' => 'required',
            'house_name'=>'required',
            'cover'=>'required',
            'daily_rent'=>'required',
            'monthly_rent'=>'required',
            'house_area'=>'required',
            'decoration'=>'required',
            'purchase_way'=>'required',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'shop_id.required' => '类型是必选的',
            'house_name.required'  => '户型名称是必填的',
            'cover.required'  => '封面图是必须的',
            'daily_rent.required'  => '日租金是必填的',
            'monthly_rent.required'  => '月租金是必填的',
            'house_area.required'  => '面积是必填的',
            'decoration.required'  => '装修程度是必选的',
            'purchase_way.required'  => '收购方式是必选的',
        ];
    }

    /**
     * {@inheritdoc}
     */
    protected function formatErrors(Validator $validator)
    {
        return Result::failure( $validator->errors()->first() )->getResult();
    }

}
